<template>
  <avue-form :option="option"
             v-model="form"></avue-form>
</template>
<script>
export default {
  data () {
    return {
      form: {
        table: [0, 2]
      },
      option: {
        column: [
          {
            label: '表格选择器',
            prop: 'table',
            type: 'table',
            multiple: true,
            children: {
              border: true,
              column: [{
                label: '姓名',
                width: 120,
                search: true,
                searchSpan: 24,
                prop: 'name'
              }, {
                label: '性别',
                prop: 'sex'
              }],
            },
            formatter: (row) => {
              if (Array.isArray(row)) {
                return row.map(ele => ele.name + '格式化').join(',')
              } else {
                return row.name + '格式化'
              }
            },
            onLoad: ({ page, value, data }, callback) => {
              //首次加载去查询对应的值
              if (value) {
                this.$message.success('首次查询' + value)
                callback([{
                  id: '0',
                  name: '张三',
                  sex: '男',
                  age: 18
                }, {
                  id: '2',
                  name: '王五',
                  sex: '女'
                }])
                return
              }
              if (data) {
                this.$message.success('搜索查询参数' + JSON.stringify(data))
              }
              if (page) {
                this.$message.success('分页参数' + JSON.stringify(page))
              }
              //分页查询信息
              callback({
                total: 2,
                data: [{
                  id: '0',
                  name: '张三',
                  sex: '男',
                  age: 18
                }, {
                  id: '1',
                  name: '李四',
                  sex: '女',
                  disabled: true,
                  age: 18
                }, {
                  id: '2',
                  name: '王五',
                  sex: '女'
                }]
              })
            },
            props: {
              disabled: 'disabled',
              label: 'name',
              value: 'id'
            }
          }]
      }
    }
  }
}
</script>